package com.yihu.cms.action;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.yihu.article.beans.Article;
import com.yihu.beans.Artwork;
import com.yihu.beans.ps.FilePath;
import com.yihu.cms.service.ArticleService;
import com.yihu.cms.service.FilePathService;
import com.yihu.cms.util.CommonUtils;

@Controller
public class FilePathController extends BaseController{
	
	private final Logger log = LoggerFactory.getLogger(ArticleController.class); 
	
	FilePathService fs = new FilePathService();

	/**
	 * 获取未初始化的图片id，做预加载使用。
	 * @return
	 */
	@RequestMapping(value = "/filePathList", method = RequestMethod.POST)
	public @ResponseBody List<FilePath> filePathList(
			@RequestParam(value = "pageCount", required = false, defaultValue = "20") int pageCount) {
		log.info("filePathList ... " );
		return fs.getFilePathList();
	}
	
	@RequestMapping(value = "/filePath", method = RequestMethod.POST)
	public @ResponseBody FilePath add(@RequestBody FilePath filePath) {
		log.info("add filePath groupName=" + 
				filePath.getGroupName() + ",path=" + filePath.getPath());
		return fs.add(filePath);
	}
	
	
	@RequestMapping(value = "/filePath/{id}", method = RequestMethod.DELETE)
	public @ResponseBody Object delete(@PathVariable("id") String id) {
		// logger.info("删除人员信息id=" + id);
		System.out.println("delete FilePath id=" + id);
		FilePath result = fs.del(id);
		return result;
	}
	
	@RequestMapping(value = "/filePath/{id}", method = RequestMethod.GET)
	public @ResponseBody Object get(@PathVariable("id") String id) {
		log.info("get artwork id=" + id);
//		return fs.getById(id);
		return JSON.toJSON(fs.getById(id));
		
	}
	
}
